package com.canbot.u05.activity.agenda.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.canbot.u05.R
import com.canbot.u05.activity.agenda.bean.AgendaDanceBean
import com.canbot.u05.activity.agenda.interfaces.IAgendaDanceLisenter

/**
 * @author yinxiaowei
 * @date 2019/5/31
 */
class AgendaDanceAdapter(private val dataList: List<AgendaDanceBean>, private val context: Context, private val iAgendaTypeLisenter: IAgendaDanceLisenter) : RecyclerView.Adapter<AgendaDanceAdapter.AgendaTypeViewHolder>() {
    private val inflater: LayoutInflater = LayoutInflater.from(context)

    override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): AgendaTypeViewHolder {
        val inflate = inflater.inflate(R.layout.activity_agenda_type_dance_item, viewGroup, false)
        return AgendaTypeViewHolder(inflate)
    }

    override fun onBindViewHolder(agendaTypeViewHolder: AgendaTypeViewHolder, i: Int) {
        val agendaTypeBean = dataList[i]
        agendaTypeViewHolder.nameDance.text = agendaTypeBean.name
        agendaTypeViewHolder.checkbox.isSelected = agendaTypeBean.isSelect
        agendaTypeViewHolder.itemView.setOnClickListener {
            iAgendaTypeLisenter.onSelect(agendaTypeBean)
        }
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    inner class AgendaTypeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        internal var checkbox: ImageView = itemView.findViewById(R.id.select)
        internal var nameDance: TextView = itemView.findViewById(R.id.name_dance)
    }
}
